﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title></title>
    <link href="/style/rightdirectory.css" rel="stylesheet" />
    <script src="/script/config.js"></script>
</head>
<style>
    th {
        text-align: center;
    }

    td {
        text-align: center;
    }

    .layer-me {
        display: none;
        margin:20px;
    }
</style>
<body>
    <div class="view-page">
        <!--搜索区域-->
        <div class="view-search inline">
            <div class="form-inline">
                <div class="form-group col-sm-2">
                    <div class="input-group">
                        <span class="input-group-addon">电话</span>
                        <input id="query" type="text" class="form-control" data-form="Phone" placeholder="电话"  >
                    </div>
                </div>
                <div class="form-group col-sm-2">
                    <div class="input-group">
                        <span class="input-group-addon">账户</span>
                        <input id="query1" type="text" class="form-control" data-form="Account" placeholder="账户"  >
                    </div>
                </div>

                <div class="form-group col-sm-2">
                    <div class="input-group">
                        <span class="input-group-addon">姓名</span>
                        <input id="query2" type="text" class="form-control" data-form="RealName" placeholder="姓名"  >
                    </div>
                </div>
                <div class="form-group col-sm-2">
                    <div class="input-group">
                        <span class="input-group-addon">IP</span>
                        <input id="query3" type="text" class="form-control" data-form="LastLoginIP" placeholder="IP">
                    </div>
                </div>
                <div class="form-group col-sm-1">
                    <button type="button" id="btn-search" class="btn btn-primary">
                        <i class="fa fa-search"></i> 搜索
                    </button>
                </div>
            </div>
        </div>
        <div class="view-eidt-btns">
            <a  href="/views/System/admintor/form.html" class="btn btn-sm">
                <i class="fa fa-plus"></i>添加
            </a>
            <a  href="javascript:;" class="btn btn-sm" data-btn-eidt="/views/System/admintor/form.html?v=">
                <i class="fa fa-edit"></i>编辑
            </a>
            <a id="amend" href="javascript:;" class="btn btn-sm">
                <i class="fa fa-edit"></i>修改密码
            </a>
            <a id="del" href="javascript:;" class="btn btn-danger btn-sm" >
                <i class="fa fa-trash-o"></i>删除
            </a>
        </div>
        <div class="view-data">
            <table id="table" class="table table-bordered table-hover" data-post="">
                <thead>
                    <tr>
                        <th class="checkboxs">
                            <label class="checkbox-reset">
                                <input type="checkbox" data-checked-table="all" />
                            </label>
                        </th>
                        <th>真实姓名</th>
                        <th>电话</th>
                        <th>邮箱</th>

                        <th>账户</th>
                        <th>账户状态</th>
                        <th>最后登录时间</th>
                        <th>最后登录ip</th>
                        <th>创建时间</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <!--分页条 默认选择id=list-page元素-->
            <div id="list-page" class="view-pagination-page"></div>
        </div>
    </div>

    <div class="layer-me">
        <div class="form-group" id="old-pass">
            <label for="exampleInputAccount2">旧密码</label>
            <input type="password"  class="form-control"  placeholder="输入旧密码"  maxlength="12">
        </div>
        <div class="form-group"  id="new-pass">
            <label for="exampleInputAccount2">新密码</label>
            <input type="password" class="form-control"  placeholder="输入新密码"  maxlength="12">
        </div>
        <button id="btn-pass" class="btn btn-info y-btn">提交</button>
    </div>
</body>

</html>
<script type="text/html" id="tp-table">
    {{each list d}}
    <tr data-eidt="{{d.Id}}">
        <td class="checkboxs">
            <label class="checkbox-reset">
                <input type="checkbox" value="{{d.Id}}" data-checked-table="single" />
            </label>
        </td>
        <td>{{d.RealName}}</td>
        <td>{{d.Phone}}</td>
        <td>{{d.Email}}</td>
        <td>{{d.Account}}</td>
        {{if d.Status==1}}
        <td>正常</td>
        {{else if d.Status==2}}
        <td>冻结</td>
        {{else if d.Status==-1}}
        <td>删除</td>
        {{/if}}
        <td>{{d.LastLoginDate|to_date}}</td>
        <td>{{d.LastLoginIP}}</td>
        <td>{{d.CreateDate|to_date}}</td>
    </tr>
    {{/each}}
</script>

<script type="text/javascript">
    $(function() {
        function _LoadData() {
            var parm = $(".view-search").getFormData();
            $("#table").ajaxPageTable("user/list", parm, function (d) {
               
                $("#table>tbody").append(template("tp-table", {
                    list: d
                }));
            })
        }
        _LoadData();//初启化
        $(".form-control").focus(function () { //搜索按钮
            $(".form-control").keydown(function(e) {
                if (e.keyCode == 13) {
                    _LoadData();
                }
            })
        })
        
        $("#btn-search").click(function() { //搜索按钮
            _LoadData();
        })

        var arr = [];
        $("#del").click(function () { //删除
            var checkbox = $("#table").getTableChecked({ type: {} });
            if (checkbox.length <= 0) {
                $.msgFall("请选择要修改的！"); return;
            }
            $.each(checkbox, function (i, item) {
                arr.push(parseInt(item));
            });
            $.alert("确定要删除嘛？", function () {
               
                $.http.json("user/del", {
                    Ids: arr
                }, {
                        pass: function (data) {
                            
                            $.msgSucceed("删除成功");
                            setTimeout(function () {
                                window.location.reload();
                            }, 2000)
                        },
                        error: function (d) {
                            console.log(d);
                        }
                    })
            })
        })
      
        $("#amend").click(function () { //修改密码
            var checkbox = $("#table").getTableChecked({ type: {}});
            if (checkbox.length<=0 || checkbox.length>=2)
            {
                $.msgFall("请选择一个修改！"); return;
            }
            console.log(checkbox);
            $.layrePage({
                content: $(".layer-me"),
                area: ['460px', '500px'] //宽高
            });
            var id = parseInt(checkbox[0]);  //转为数字
            $("#btn-pass").click(function () { //修改密码提交按钮
                var reg = /\S{2,10}/;
                if (!$("#old-pass input").val().match(reg)|!$("#new-pass input").val().match(reg)) {
                    $.msgFall("请正确输入！")
                    return
                }
                $.http.json("user/updpwd", {   
                    Id: id,
                    pwd: $("#old-pass input").val(),
                    newpwd: $("#new-pass input").val()
                }, {
                        pass: function (data) {
                            $.msgSucceed(data.Errmsg)
                        },
                        error: function (d) {
                            $.msgFall(d.Errmsg)
                        }
                })
            })
            return;
            });
    })
</script>